package cn.driver.servicecourse.controller;


import cn.driver.common.pojo.Course;
import cn.driver.common.tools.ResponseData;
import cn.driver.servicecourse.service.CourseService;
import cn.driver.servicecourse.utils.Pager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 科目控制层
 */

@Api(tags = "科目接口")
@RestController
@CrossOrigin
@RequestMapping("/course")
public class CourseController {
    @Autowired
    private CourseService courseService;

    @ApiOperation("分页信息")
    @GetMapping("/pageInfo")
    public ResponseData pageInfo(@RequestParam Integer pageNo, @RequestParam Integer pageSize, @RequestParam(required = false) String prm) {
        Pager<Course> pagerInfo = courseService.pageInfo(pageNo, pageSize, prm);
        return ResponseData.ok(pagerInfo);
    }

    @ApiOperation("/添加")
    @PostMapping("/addCourse")
    public ResponseData addCourse(Course course){
        int count = courseService.add(course);
        if (count>0){
            return ResponseData.ok("添加成功");

        }else {
            return ResponseData.error("添加失败");
        }
    }

    @ApiOperation("/修该")
    @PostMapping("/updateCourse")
    public ResponseData updateCourse(Course course){
        int count = courseService.update(course);
        if (count>0){
            return ResponseData.ok("修该成功");

        }else {
            return ResponseData.error("修该失败");
        }
    }

    @ApiOperation("删除")
    @PostMapping("/delCourse")
    public ResponseData delCourse(int id){
        int count =courseService.del(id);
        if (count>0) {
            return ResponseData.ok("删除成功");
        }else {
            return ResponseData.error("删除失败");
        }
    }
}
